package com.hd.boot.dao;

import com.hd.boot.pojo.Teacher;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class TeacherDao {
    private static Map<Integer, Teacher> teacherMap=null;
    private Teacher teacher=new Teacher();

    static {
        teacherMap=new HashMap<Integer, Teacher>();
        //添加数据
        teacherMap.put(1,new Teacher(1,"晓晓","数学"));
        teacherMap.put(2,new Teacher(2,"莉莉","英语"));
        teacherMap.put(3,new Teacher(3,"小凯 ","音乐"));
        teacherMap.put(4,new Teacher(4,"小王","画画"));
    }
    public Collection<Teacher> allTea(){
        return  teacherMap.values();
    }
    //删除
    public void delTea(int teaId){
        teacherMap.remove(teaId);
    }
    //添加
    static  int teaId=3;
    public void saveTea(Teacher teacher){
        if (teacher.getTeaId()==null){
            teacher.setTeaId(teaId++);
        }
        teacherMap.put(teacher.getTeaId(),teacher);
    }

}
